package com.flash.BusinessParameters.controller;

import com.flash.BusinessParameters.entity.Plate;
import com.flash.BusinessParameters.service.PlateService;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 这是股票板块的控制层
 * @author 刘曦
 * @since 2022-8-11
 * @version 1.0
 */
@Controller
public class PlateController {
    @Resource
    PlateService plateService;

    /**
     * 查询出网页需要的数据
     * @return 返回的map里包含分页以及Plate集合
     */
    @RequestMapping("/selectPlate")
    @ResponseBody
    public Map selectPlate(){
        HashMap map = new HashMap();
        List<Plate> plates = plateService.selectPlate();
        int i = plateService.selectCountPlate();
        System.out.println(plates);
        System.out.println(i);
        map.put("code","0");
        map.put("msg","");
        map.put("count",i);
        map.put("data",plates);
        return map;
    }
    /**
     * 添加板块的方法
     * @param plate 存储子版块数据的对象
     * @return 返回是否添加成功的字符串
     */
    @RequestMapping("/insertPlate")
    public String insertPlate(Plate plate){
        int i = plateService.insertPlate(plate);
        System.out.println(i);
        if (i>0){
            return "ok";
        }else {
            return "no";
        }
    }
    /**
     * 添加板块的方法
     * @param plate 存储父版块数据的对象
     * @return 返回是否添加成功的字符串
     */
    @RequestMapping("/insertFatherPlate")
    public String insertFatherPlate(Plate plate){
        plate.setPlateFatherId("000");
        int i = plateService.insertFatherPlate(plate);
        System.out.println(i);
        if (i>0){
            return "ok";
        }else {
            return "no";
        }
    }
    /**
     *修改股票板块数据的方法
     * @param plate 封装股票板块数据的对象
     * @return 返回修改了多少条数据
     */
    @RequestMapping("toUpdatePlate")
    public int updatePlate(Plate plate){
        int i = plateService.updatePlate(plate);
        return i;
    }
    /**
     *删除数据的方法
     * @param plateId 根据Id删除数据
     * @return 返回删除了多少条数据
     */
    @RequestMapping("/deletePlate")
    public int deletePlate(String plateId){
        int i = plateService.deletePlate(plateId);
        return i;
    }
}
